package com.bdqn.tour.servlet.comments;

import com.bdqn.tour.dao.HotelImplementationClass;
import com.bdqn.tour.dao.impl.ImplUersDao;
import com.bdqn.tour.entity.Comment;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@WebServlet("/SelectServletUser")
public class SelectServletUser extends HttpServlet {
    private HotelImplementationClass commentDAO;

    @Override
    public void init() throws ServletException {
        super.init();
        // 初始化 CommentDAO
        commentDAO = new ImplUersDao();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 设置请求编码
        req.setCharacterEncoding("UTF-8");

            Comment comment = new Comment();
            String name=comment.getUsername();
            // 从数据库中获取所有评论
            List<Comment> comments = commentDAO.getAllComments();

            // 将评论列表设置到请求属性
            req.setAttribute("commentsList", comments);

            // 转发到 JSP 页面
            req.getRequestDispatcher("HotelReviews.jsp").forward(req, resp);
    }
}
